import React, { createRef, PureComponent } from 'react';
import UserList from './UserList.js';
import { uploadToGithub } from '@/api/common/upload';
import { Button } from 'antd';
class User extends PureComponent {
  state = { loading: false };
  private readonly refFile;
  constructor(props) {
    super(props);
    this.refFile = createRef();
  }

  render() {
    const { loading } = this.state;
    return (
      <div>
        <input type="file" ref={this.refFile} id="file" />
        <Button
          loading={loading}
          onClick={async () => {
            this.setState({ loading: true });
            const file = this.refFile.current.files[0];
            console.dir(file);
            const [err, res] = await uploadToGithub(file.name, file);
            if (err) {
              console.log(res, 'err');
            }
            console.log(res);
            this.setState({ loading: false });
          }}
        >
          上传
        </Button>
        <UserList />
      </div>
    );
  }
}

export default User;
